<template>
	<view class="detail" v-if="user">
		<!-- <u-navbar @leftClick="leftClick" leftText="返回" title="个人详情" placeholder fixed>
		</u-navbar> -->
		<u-navbar title="个人详情" placeholder fixed>
			<view class="navbar-left-text" slot="left">
				<view v-if="!isShowBackHome"  @click="leftClick" class="">返回</view>
			</view>
			<view class="navbar-left-text" slot="left">
				<uni-icons v-if="isShowBackHome" type="home-filled" size="24" style="margin-left: 10rpx;" @click="goHome"></uni-icons>
			</view>
		</u-navbar>
		
		<scroll-view scroll-y="true" class="main"  @scrolltolower="lower()">
			<view class="user" v-if="user">
				<image :src="oss(user.avatar)" mode="" class="avatar"></image>
				<view class="info">
					<view class="t">
						<view class="l">{{user.nickname}}</view>
						<image v-if="user.gender === 0" src="../../static/boy.png" class="sex" mode=""></image>
						<image v-else src="../../static/girl.png" class="sex" mode=""></image>
					</view>
				</view>
				<view class="btn active" v-if="user.follow > 0"  @click="follow(0)">已关注</view>
				<view class="btn active" v-else @click="follow(1)">关注</view>
			</view>
			
			<view class="report">
				<view class="" style="flex: 1;"></view>
				<view @click="center = true" class="jb">举报</view>
				<view class="lh" @click="block">拉黑</view>
			</view>
			
			<view class="desc">
				<view class="l">个人性格：</view>
				<view class="r">性格开朗，好沟通，做事认真负责</view>
			</view>
			<view class="covers" v-if="user.video">
				<video class="cover" :src="oss(user.video)"></video>
				<!-- <view class="overlay" v-if="data.switch != 1">该用户暂无开通视频功能</view> -->
			</view>
			<!-- <view class="title">经验</view>
			<view class="expire" v-html="user.experiencecontent"></view>
			<view class="title">资格证书</view>
			<view class="imgBox">
				<image v-for="(item,index) in user.certimages" :key="index" :src="item" mode="" class="cert"   @click="preview(item)"></image>
			</view> -->
			<view class="title">技能</view>
			<view class="list" v-for="(item, index) of list" :key="index" @click="detail(item.id)">
				<image :src="oss(item.images[0])" class="cover" mode=""></image>
				<view class="info">
					<view class="t">{{item.name}}</view>
					<view class="b">{{item.cateName}}</view>
					
				</view>
				<view class="numBox"><text class="icon">¥</text>{{item.price}}/{{item.unit_price}}</view>
			</view>
			
		</scroll-view>
		<view class="btns" @click="mobileShow">电话联系</view>
		<u-popup :show="show" @close="show = false" @open="show = true" mode="center" round="20">
			<view class="userBox">
				<image :src="oss(user.avatar)" class="avatar" mode=""></image>
				<view class="name">{{user.nickname}}</view>
				<view class="tel">联系电话：{{user.mobile}}</view>
				<view class="info">联系对方时，请告知对方，我们是从哪个平台上看到的</view>
				<view class="btns" @click="tel">拨打</view>
			</view>
		</u-popup>
		<u-popup :show="show1" @close="show1 = false" mode="center">
		          <image :src="url" mode="widthFix" style="width: 750rpx;" @click="show1 = false"></image>
				</u-popup>
				
				
				<u-popup mode="center" :round="10" :show="center" @close="close" @open="open">
					<view class="popup-center">
						<view class="title">举报内容</view>
						<view class="input">
							<!-- <input v-model="nickname" placeholder="请输入新的昵称" type="text"> -->
							<u--textarea v-model="content" placeholder="请填写举报内容..." autoHeight ></u--textarea>
						</view>
						<view class="btn">
							<view @click="center = false" class="cancel">取消</view>
							<view @click="submit" class="confirm">确定</view>
						</view>
					</view>
				</u-popup>
				
				
				<view class="share-box">
					<button class="iconfont icon-yaoqing" style="width: 110rpx;height: 110rpx;z-index: 99;" open-type="share"></button>
					<image class="fenx-img" src="../../static/fenx.png" mode=""></image>
				</view>
				<text class="fenxiang">分享</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				finish: false,
				user: '',
				list: [],
				show: false,
				show1: false,
				url: '',
				center: false,
				content:'',
				id:'',
				isShowBackHome:false
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getdetail(options.id)
			
			let pages = getCurrentPages()
			if(pages.length === 1){
				this.isShowBackHome = true
			}
		},
		methods:{
			goHome(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			leftClick(){
			    uni.navigateBack()
		    },
			mobileShow(){
				if(!uni.getStorageSync('token')){
					uni.$u.route({
						url: 'pagesA/auth/login'
					})
					return
				}
				this.show = true
			},
			submit(){
				if (!this.content) {
					uni.$u.toast('请输入举报内容');
					return;
				}
				uni.$u.http.post('/report', {
					content:this.content
				}).then(res => {
					if (res.code == 1) {
						this.center = false
						uni.$u.toast(res.msg);
						this.content = ''
					}
				}).catch((res) => {
				
				})
			},
			open() {
				// console.log('open');
			},
			close() {
				this.center = false
				// console.log('close');
			},
			change(e) {
				console.log('change', e);
			},
			//拉黑
			block(){
				uni.$u.toast('已拉黑');
			},
			preview(url) {
				this.show1 = true
				this.url = this.oss(url)
			},
			follow(status ) {
				uni.$u.http.post('/follow', {
					user_id: this.user.id,
					status : status
				}).then(res => {
					if (res.code == 1) {
						this.user.follow =  status
					}
				}).catch((res) => {
				
				})
			},
			detail(id) {
				uni.$u.route({
					url: 'pages/serve/skill',
					params: {
						id: id
					}
				})
			},
			tel() {
				uni.$u.http.post('/mobilelog',{
					mobile:this.user.mobile
				}).then(res => {
					if (res.code == 1) {
						uni.makePhoneCall({
							phoneNumber: this.user.mobile
						});
					}
				}).catch((res) => {
				
				})
			},
			lower() {
				this.page++
				this.getdetail()
			},
			getdetail(id) {
				if(this.finish){
					return
				}
				uni.$u.http.post('/skilllist', {
					user_id: this.id,
					page: this.page
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data.list)
						if(res.data.user.certimages) {
							res.data.user.certimages = res.data.user.certimages.map((value) => {
								return this.oss(value)
							})
						} else {
							res.data.user.certimages = []
						}
						 
						 this.user = res.data.user
						 console.log(this.user)
						 
						// this.detail = res.data
						// console.log(this.detail)
						if(res.data.list.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {
				
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

	.detail {
		height: 100vh;
		overflow: hidden;
		position: relative;
		.userBox{
			width: 520rpx;
			height: 540rpx;
			border-radius: 30rpx;
			background-color: #FFFFFF;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 0 50rpx;
			box-sizing: border-box;
			.avatar{
				width: 170rpx;
				height: 170rpx;
				border-radius: 50%;
				border-radius: 50%;
				margin-top: -80rpx;
				margin-bottom: 20rpx;
			}
			.name{
				color: #191615;
				font-size: 36rpx;
				margin-bottom: 20rpx;
			}
			.tel{
				color: #191615;
				font-size: 30rpx;
				margin-bottom: 20rpx;
			}
			.info{
				background-color: #FFFAE5;
				border: 10rpx;
				padding: 20rpx;
				color: #FF8007;
				font-size: 22rpx;
				margin-bottom: 40rpx;
			}
			.btns{
				background: linear-gradient(to right, #FFDF41, #FFC141);
				display: flex;
				align-items: center;
				justify-content: center;
				width: 400rpx;
				height: 72rpx;
				color: #191615;
				font-size: 30rpx;
				border-radius: 36rpx;
			}
		}
		
		.popup-center {
			width: 600rpx;
			min-height: 360rpx;
		
			.title {
				text-align: center;
				margin-top: 46rpx;
				font-size: 34rpx;
			}
		
			.input {
				width: 480rpx;
				// height: 92rpx;
				background-color: #F7F7F7;
				margin: auto;
				margin-top: 46rpx;
				text-align: center;
		
				input {
					position: relative;
					top: 20rpx;
				}
			}
		
			.btn {
				width: 100%;
				height: 90rpx;
				margin-top: 20rpx;
				display: flex;
				// background-color: darkcyan;
		
				.cancel {
					width: 49%;
					height: 100%;
					text-align: center;
					line-height: 90rpx;
					font-size: 28rpx;
					color: #999;
					border-top: 1rpx solid #f3f3f3;
					border-right: 1rpx solid #f3f3f3;
				}
		
				.confirm {
					width: 49%;
					text-align: center;
					line-height: 90rpx;
					font-size: 28rpx;
					color: #FEBF4E;
					border-top: 1rpx solid #f3f3f3;
				}
			}
		}
		.main{
			overflow: hidden;
			position: absolute;
			left: 0;
			width: 100%;
			bottom: 120rpx;
			top: 0;
		}
		.btns{
			background: linear-gradient(to right, #FFDF41, #FFC141);
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			color: #191615;
			border-radius: 44rpx;
			width: 590rpx;
			position: absolute;
			left: 80rpx;
			bottom: 20rpx;
			flex-shrink: 0;
			font-weight: bold;
		}
		.user {
			display: flex;
			align-items: center;
			padding: 20rpx;

			.avatar {
				width: 130rpx;
				height: 130rpx;
				margin-right: 20rpx;
				border-radius: 50%;
			}

			.info {
				flex: 1;

				.t {
					display: flex;
					align-items: center;

					.l {
						font-size: 40rpx;
						color: #191615;
						font-weight: bold;
					}

					.sex {
						flex-shrink: 0;
						width: 27rpx;
						height: 25rpx;
					}
				}
			}

			.btn {
				background: linear-gradient(to right, #FFDF41, #FFC141);
				width: 140rpx;
				height: 58rpx;
				border-radius: 29rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 29rpx;
				color: #191615;
				font-weight: bold;
			}

			.active {
				box-sizing: border-box;
				border: 1px solid #D5D5D5;
				background: #fff;
			}
		}
		
		.report {
			display: flex;
			position: relative;
			top: -30rpx;
			
			.jb {
				font-size: 24rpx;
				background-color: #FEBF4E;
				padding: 5rpx 20rpx;
				align-items: center;
				border-radius: 20rpx;
				margin-right: 20rpx;
			}
			.lh {
				font-size: 24rpx;
				background-color: #FEBF4E;
				padding: 5rpx 20rpx;
				align-items: center;
				border-radius: 20rpx;
				margin-right: 20rpx;
			}
		}
		
		.covers{
			width: 686rpx;
			height: 420rpx;
			position: relative;
			margin: auto;
			margin-top: 32rpx;
					padding: 20rpx 0;
					.cover{
						width: 100%;
					}
					.overlay {
					  position: absolute;
					  top: 0;
					  left: 0;
					  width: 100%;
					  height: 420rpx;
					  backdrop-filter: blur(10px); /* 添加模糊效果 */
					  text-align: center;
					  line-height: 400rpx;
					  font-size: 24rpx;
					  color: #FEBF4E;
					}
				}

		.desc {
			display: flex;
			align-items: center;
			padding: 0 20rpx;

			.l {
				font-size: 28rpx;
				color: #999999;
			}

			.r {
				color: #575859;
				font-size: 28rpx;
			}
		}

		.title {
			color: #191615;
			font-size: 34rpx;
			padding: 30rpx 20rpx 10rpx;
			font-weight: bold;
		}
		.imgBox{
			display: flex;
			flex-wrap: nowrap;
			padding-left: 20rpx;
			overflow-y: auto;
			.cert{
				width: 200rpx;
				height: 300rpx;
				flex-shrink: 0;
				margin-right: 20rpx;
			}
		}

		.expire {
			color: #575859;
			font-size: 24rpx;
			line-height: 40rpx;
			padding: 0 20rpx;
		}
		.list{
			margin: 0 20rpx 20rpx;
			background-color: #fff;
			box-shadow: 0 0 10rpx rgba(98, 98, 98, 0.2);
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			padding: 20rpx;
			.cover{
				width: 120rpx;
				height: 120rpx;
				border-radius: 10rpx;
			}
			.info{
				flex: 1;
				margin: 0 20rpx;
				.t{
					font-weight: bold;
					font-size: 32rpx;
					color: #191615;
				}
				.b{
					color: #999999;
					font-size: 30rpx;
				}
			}
			.numBox{
				font-size: 40rpx;
				color: #FF5B1A;
				font-weight: bold;
				.icon{
					font-size: 30rpx;
				}
			}
		}

	}
	
	
	.fenxiang {
		font-size: 24rpx;
		position: fixed;
		bottom: 45%;
		right: 50rpx;
		z-index: 9;
	}
	.share-box {
		position: fixed;
		bottom: 40%;
		right: 29rpx;
		z-index: 9;
		
		.fenx-img {
			width: 100rpx;
			height: 100rpx;
			position: relative;
			top: -100rpx;
		}
	}
	/* button自带样式清除 */
	.share-box button::after {
	  border: none !important;
	  padding: 0 !important;
	  margin: 0 !important;
	}
	
	.share-box button {
	  background-color: transparent !important;
	  padding: 0 !important;
	  line-height: inherit !important;
	  margin: 0 !important;
	  width: auto !important;
	  font-weight: 500 !important;
	  border-radius: none !important;
	}
</style>
